<template>
    <div class="detailBox animated fadeInUp">
        <titles>
            <template v-slot:project_ri>
                <li class="project_right">
                    <button @click="goback">
                        返回
                    </button>
                </li>
            </template>
        </titles>
        <div class="detail_box">
            <card :type="2" :itemData="list" @lookImg="openImg" @addComment="myAddComment">
                <template v-slot:card_img>
                    <div class="imgBox_out" v-if="list.art_img">
                        <div class="imgBox" v-for="(item, index) in list.art_img.split(',')">
                            <div @click="openImg(item)">
                                <el-icon color="#FFFFFF" :size="25"><zoom-in /></el-icon>
                            </div>
                            <img :src="item" alt="">
                        </div>
                    </div>
                </template>
            </card>
            <div class="ommentCard_box" v-if="commentList">
                <commentCard @addComment="myAddComment" @lookImg="openImg" v-for="(item, index) in commentList"
                    :commentData="item"></commentCard>
            </div>

        </div>
    </div>
    <el-dialog v-model="dialogVisible">
        <div class="Magnify">
            <img  w-full :src="dialogImageUrl" alt="Preview Image" />
        </div>
        
    </el-dialog>
</template>

<script setup>
import axios from "axios";
import { ZoomIn } from '@element-plus/icons-vue'
import titles from './title.vue'
import card from './card.vue'
import commentCard from './commentCard.vue'
import { useRouter } from 'vue-router'
import { onBeforeMount, ref } from 'vue'
const router = useRouter()
const dialogVisible = ref(false)
const dialogImageUrl = ref('')
const list = ref()
const Id = ref()
const commentList = ref()
const goback = () => {
    router.back()
}
onBeforeMount(() => {
    Id.value = router.currentRoute.value.query.id
    getdetail()
})
const myAddComment = () => {
    console.log('11111')
    getDetailList()
}
const getdetail = () => {
    axios({
        url: '/Article/detail',
        baseURL: 'http://kaoshiguanli.haimijiaoyu.com/api/',
        method: 'post',
        data: { id: Id.value }
    }).then(res => {
        list.value = res.data.data
        getDetailList()
        // console.log(list.value,"8888888888")
    })
}
const getDetailList = () => {
    axios({
        url: '/Article/comment_list',
        baseURL: 'http://kaoshiguanli.haimijiaoyu.com/api/',
        method: 'post',
        data: { article_id: Id.value }
    }).then(res => {
        commentList.value = res.data.list
    })
}
const openImg = (url) => {
    dialogImageUrl.value = url
    dialogVisible.value = true
}
//
</script>

<style lang="scss" scoped>
@media screen and (min-width:1200px) {
    .Magnify{
        display: flex;
        justify-content: center;
        padding-bottom: 30px;
        img{
            max-width: 100%;
        }
    }
    .detailBox {
        min-height: 500px;
    }

    .project_right {
        button {
            padding: 5px 15px;
            font-size: 16px;
            color: #FFFFFF;
            background-color: #1CABD9;
            border-radius: 25px;
            border: none;
            display: flex;
            align-items: center;

            img {
                width: 21px;
                height: 21px;
                margin-right: 10px;
            }
        }
    }

    .imgBox_out {
        display: flex;
        flex-wrap: wrap;
        width: 1000px;
    }

    .imgBox {
        width: 100px;
        height: 100px;
        padding: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        box-shadow: 0px 0px 4px 4px rgba(0, 0, 0, 0.03);
        margin-right: 20px;
        margin-bottom: 20px;
        div {
            width: 100%;
            height: 100%;
            position: absolute;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: rgba($color: #000000, $alpha: 0.4);
            opacity: 0;
            transition: all 0.6s;

        }

        img {
            max-width: 100px;
        }

        div:hover {
            opacity: 1;
        }
    }

    // .imgBox:after {
    // 	content: ""; 
    // 	width: 240px;
    // }
    .detail_box {
        width: 1000px;
        margin: 0 auto;
        min-height: 500px;
        padding-bottom: 60px;

        .ommentCard_box {
            background: #FFFFFF;
            box-shadow: 0px 0px 4px 4px rgba(0, 0, 0, 0.03);
            border-radius: 10px 10px 10px 10px;
        }
    }
}

@media screen and (max-width: 1200px) {
    .Magnify{
        display: flex;
        justify-content: center;
        padding-bottom: 30px;
        img{
            max-width: 100%;
        }
    }
    // .imgBox {
    //     width: 89vw;
    //     display: flex;
    //     flex-wrap: wrap;
    //     justify-content: space-between;

    //     img {
    //         min-width: 25vw;
    //     }
    // }

    // .imgBox:after {
    //     content: "";
    //     width: 25vw;
    // }

    .detailBox {
        min-height: 61vh;
        padding-top: 4vw;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .project_right {
        button {
            padding: 0.5vw 3vw;
            font-size: 2.13vw;
            color: #FFFFFF;
            background-color: #1CABD9;
            border-radius: 3vw;
            border: none;
            display: flex;
            align-items: center;
        }
    }

    .detail_box {
        width: 95vw;
        margin: 0 auto;
        min-height: 61vh;

        .ommentCard_box {
            background: #FFFFFF;
            box-shadow: 0px 0px 4px 4px rgba(0, 0, 0, 0.03);
            border-radius: 1.3vw;
        }
    }
    .imgBox_out {
        display: flex;
        flex-wrap: wrap;
        width: 95vw;
        margin-top: 2vw;
    }

    .imgBox {
        width: 15vw;
        height: 15vw;
        padding: 3vw;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        box-shadow: 0px 0px 4px 4px rgba(0, 0, 0, 0.03);
        margin-right: 3vw;
        margin-bottom: 3vw;
        div {
            width: 100%;
            height: 100%;
            position: absolute;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: rgba($color: #000000, $alpha: 0.4);
            opacity: 0;
            transition: all 0.6s;

        }

        img {
            // max-width: 100%;
            width: 100%;
        }

        div:hover {
            opacity: 1;
        }
    }
}</style>